<template>
  <el-aside>
    <div class="menu-title">
      <img src="../assets/icons/logo.png">
      <h1>任我行</h1>
    </div>
    <el-menu mode="vertical" active-text-color="#ffd04b" class="el-menu-vertical-demo" background-color="#545c64"
      text-color="#fff" :collapse="false" @open="handleOpen" @close="handleClose">
      <el-menu-item :index="item.path" v-for="item in list" :key="item.path" @click="clickMenu(item)">
        <component class="icons" :is="item.icon"></component>
        <span style="margin-left: 10px">{{ item.label }}</span>
      </el-menu-item>
    </el-menu>
  </el-aside>
</template>
<script setup>
import { useRouter } from 'vue-router';
import { reactive } from "vue";
import { useList } from '../store/index'
// import { storeToRefs } from 'pinia';



//引入pinia actions方法更新面包屑数据
const store = useList()
const list = reactive([
  {
    path: "/",
    name: "center",
    label: "任务中心",
    icon: "house",
    url: "Center/Center",
  },
  {
    path: "/group",
    name: "group",
    label: "群组",
    icon: "UserFilled",
    url: "Group/Group",
  },
])

const router = useRouter();
/**
 * router 路由实例
 * route 当前路由
 */
function clickMenu(item) {
  //点击路由跳转，当跳转路由和当前路由不一致才允许跳转
  if (item.path !== router.path) {
    router.push({ name: item.name })
  }
  //更新面包屑数据
  store.selectMenu(item)

}
const handleOpen = (key, keyPath) => { console.log(key, keyPath); }
const handleClose = (key, keyPath) => { console.log(key, keyPath); }



</script>
<style lang="less" scoped>
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
}

.menu-title {
  width: 200px;
  height: 56px;
  background-color: #535f6b;
  color: #fff;
  padding-left: 40px;

  img {
    display: inline-block;
    width: 28px;
    height: 28px;
    vertical-align: middle;
    line-height: 56px;
    margin-right: 5px;
  }

  h1 {
    display: inline-block;
    vertical-align: middle;
    line-height: 56px;
  }
}


.icons {
  width: 16px;
  height: 16px;
}

.el-menu {
  border: none;
}
</style>